package com.easy.persondemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.easylib.base.BaseActivity;
import com.guyj.CommonAdapter;
import com.guyj.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

public class MainActivity extends BaseActivity {

    @Bind(R.id.recycler)
    RecyclerView recycler;
    @Bind(R.id.activity_main)
    LinearLayout activityMain;
    GridLayoutManager glm;
    List<UserBean> datas;


    @Override
    public int getContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0x01) {
            if (resultCode == RESULT_OK) {
                finish();
            }
        }
    }

    @OnClick(R.id.iv_pic)
    public void onclick() {
        Intent intent = new Intent(mContext, InfoActivity.class);
        startActivityForResult(intent, 0x01);
    }

    @Override
    protected void initVariable() {
        datas = new ArrayList<>();
        datas.add(new UserBean("邵某某", "市科技局", "1978.06", "西藏某某县委常务副书记，苍南县副县长（正县长级）", "市科技局局长、党委书记，市地震局局长"));
        datas.add(new UserBean("朱某某", "市城管与执法局", "1971.05", "市发改委副县长级干部，青海省海西州格尔木市委常委、副市长", "市城管与执法局副局长、党组成员"));
        datas.add(new UserBean("朱三某", "市铁投集团", "1975.12", "市城投集团副总经理、党委委员", "市铁投集团总经理、副董事长、党委副书记"));
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        recycler.setLayoutManager(glm = new GridLayoutManager(mContext, 1));
        recycler.setAdapter(new CommonAdapter<UserBean>(mContext, R.layout.item_head_name_hor, datas) {
            @Override
            protected void convert(ViewHolder viewHolder, UserBean o, int i) {
                viewHolder.setText(R.id.tv_name, datas.get(i).name);
                viewHolder.setText(R.id.tv_1, datas.get(i).danwei);
                viewHolder.setText(R.id.tv_2, datas.get(i).chusheng);
                viewHolder.setText(R.id.tv_3, datas.get(i).oldzhifu);
                viewHolder.setText(R.id.tv_4, datas.get(i).newzhifu);
                switch (i) {
                    case 0:
                        ((ImageView) viewHolder.getView(R.id.iv_head)).setImageResource(R.drawable.head1);
                        break;
                    case 1:
                        ((ImageView) viewHolder.getView(R.id.iv_head)).setImageResource(R.drawable.head2);
                        break;
                    case 2:
                        ((ImageView) viewHolder.getView(R.id.iv_head)).setImageResource(R.drawable.head3);
                        break;
                }
                viewHolder.setOnClickListener(R.id.ll_root, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, InfoActivity.class);
                        startActivityForResult(intent, 0x01);
                    }
                });
            }
        });
    }

}
